package com.oscar.ehome.view.pageview;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.base.activity.BasesActivity;
import com.oscar.ehome.bean.pagebean.YeJiXiangQingBean;
import com.oscar.ehome.presenter.PagePresenter;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.CommonUtils;
import com.oscar.ehome.utils.view.MyImageView;
import com.oscar.ehome.utils.view.progressview.ProgressFrameLayout;
import com.oscar.ehome.utils.xrefresh.XRefreshView;
import com.oscar.ehome.utils.xrefresh.XScrollView;
import com.oscar.ehome.view.pageview.view.YejiChaXunXiangQingView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by juxing
 * author: SunHaoZhao
 * date: On 2018/4/18
 */

public class YeJiChaXunXiangQing extends BasesActivity<YejiChaXunXiangQingView, PagePresenter> implements YejiChaXunXiangQingView, XRefreshView.XRefreshViewListener,
        ProgressFrameLayout.AgainRequestListener {

    @BindView(R.id.title_img_back)
    ImageView titleImgBack;
    @BindView(R.id.title_tv_menu)
    TextView titleTvMenu;
    @BindView(R.id.title_layout_left)
    RelativeLayout titleLayoutLeft;
    @BindView(R.id.title_topbar)
    TextView titleTopbar;
    @BindView(R.id.img_spinner)
    ImageView imgSpinner;
    @BindView(R.id.liear_title)
    LinearLayout liearTitle;
    @BindView(R.id.title_tv_right)
    TextView titleTvRight;
    @BindView(R.id.title_img_right)
    ImageView titleImgRight;
    @BindView(R.id.title_img_right_new)
    ImageView titleImgRightNew;
    @BindView(R.id.title_img_right_dudao)
    ImageView titleImgRightDudao;
    @BindView(R.id.home_tv_num)
    TextView homeTvNum;
    @BindView(R.id.title_right_layput)
    RelativeLayout titleRightLayput;
    @BindView(R.id.basetitle_bar)
    RelativeLayout basetitleBar;
    @BindView(R.id.touxiang_img)
    MyImageView touxiangImg;
    @BindView(R.id.name_text)
    TextView nameText;
    @BindView(R.id.xingbie_img)
    ImageView xingbieImg;
    @BindView(R.id.sss)
    XScrollView sss;
    @BindView(R.id.phone_text)
    TextView phoneText;
    @BindView(R.id.dangriyushou_text)
    TextView dangriyushouText;
    @BindView(R.id.zhiji_text)
    TextView zhijiText;
    @BindView(R.id.dangyueyushou_text)
    TextView dangyueyushouText;
    @BindView(R.id.dangyuechengbao_text)
    TextView dangyuechengbaoText;
    @BindView(R.id.nianduyushou_text)
    TextView nianduyushouText;
    @BindView(R.id.niandushengbao_text)
    TextView niandushengbaoText;
    @BindView(R.id.dangyuexinzeng_text)
    TextView dangyuexinzengText;
    @BindView(R.id.dangyuexinzengyouxiao_text)
    TextView dangyuexinzengyouxiaoText;
    @BindView(R.id.dangyuexinzengshidong_text)
    TextView dangyuexinzengshidongText;
    @BindView(R.id.leijizengyuan_text)
    TextView leijizengyuanText;
    String id, data, token;
    PagePresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yejichaxunxiangqing);
        ButterKnife.bind(this);
        basetitleBar.setBackgroundColor(Color.parseColor(SystemConfigFactory.getInstance(YeJiChaXunXiangQing.this).getSystemConfig().getColor()));
        initView();
        initData();
    }

    /**
     * 初始化
     */
    public void initView() {
        titleImgBack.setImageResource(R.mipmap.fanhui);

        titleImgBack.setVisibility(View.VISIBLE);
        titleTopbar.setText("业绩查询");
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        Intent in = getIntent();
        id = in.getStringExtra("id");
        data = in.getStringExtra("data");

        token = SystemConfigFactory.getInstance(YeJiChaXunXiangQing.this).getSystemConfig().getToken();
        presenter = new PagePresenter(this);

    }

    public void initData() {
        if (CommonUtils.isNetConn(this)) {

            presenter.getyejixiangqing(token, id, data);
        }
    }

    @OnClick({R.id.title_layout_left})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.title_layout_left://返回
                finish();
                break;
        }
    }
    @Override
    public void getyejixiangqing(YeJiXiangQingBean result) {
        dismissLoading();
        if (result != null  ) {
            nameText.setText(result.getUser().getName());
            GildeUtils.loadUrlImage4(C.qiniu_ip + result.getUser().getPhoto(),touxiangImg, YeJiChaXunXiangQing.this);
            phoneText.setText(result.getUser().getMobile());
            zhijiText.setText(result.getUser().getRoleMobile().getRoleName());
            if(result.getUser().getSex().equals("男")){
                xingbieImg.setImageResource(R.mipmap.nan);
            }else{
                xingbieImg.setImageResource(R.mipmap.nv);
            }
            dangriyushouText.setText(result.getValue1()+"元");
            dangyueyushouText.setText(result.getValue2()+"万元");
            dangyuechengbaoText.setText(result.getValue3()+"万元");
            nianduyushouText.setText(result.getValue4()+"万元");
            niandushengbaoText.setText(result.getValue5()+"万元");
            dangyuexinzengText.setText(result.getValue6()+"人");
            dangyuexinzengyouxiaoText.setText(result.getValue7()+"人");
            dangyuexinzengshidongText.setText(result.getValue8()+"人");
            leijizengyuanText.setText(result.getValue9()+"人");
        }
    }

    @Override
    public void erroy() {

    }

    @Override
    public void erry(String result) {

    }

    @Override
    public void againRequest() {

    }

    @Override
    protected PagePresenter createPresenter() {
        presenter = new PagePresenter(this);
        return presenter;
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onRefresh(boolean isPullDown) {

    }

    @Override
    public void onLoadMore(boolean isSilence) {

    }

    @Override
    public void onRelease(float direction) {

    }

    @Override
    public void onHeaderMove(double headerMovePercent, int offsetY) {

    }
}
